<?
$VUE["includes"][]="includes/tiny_mce/jquery.tinymce.js";

if(isset($_REQUEST["action"])){
	if($_REQUEST["action"]=="enregistrer_configuration"){
		
		foreach($_REQUEST as $param=>$valeur){
			if(substr($param,0,4)=="cfg_"){
				if(is_array($valeur)){
					$tmp="";
					foreach($valeur as $val) $tmp.=",".$val;
					$sql->query("update ".CFG_MYSQL_PREFIX."module_config set valeur='".substr($tmp,1)."' where module='news' and nom='".substr($param,4)."'");				
				}else{
					$sql->query("update ".CFG_MYSQL_PREFIX."module_config set valeur='".$valeur."' where module='news' and nom='".substr($param,4)."'");
				}
			}
		}
		
	}
	
	if($_REQUEST["action"]=="ajouter_news"){
		if(($_REQUEST["titre"]!="")&&($_REQUEST["texte"]!="")&&($_REQUEST["auteur"]!="")&&($_REQUEST["date"]!="")){
			$tmp=preg_replace("/(\d{2})\/(\d{2})\/(\d{4})/","$3-$2-$1",$_REQUEST["date"]);
			//echo $tmp;
			$ts=strtotime($tmp);
			//echo $_REQUEST["date"]." ".$ts;
			$var=null;
			$var->titre=$_REQUEST["titre"];
			$var->texte=$_REQUEST["texte"];
			$var->auteur=$_REQUEST["auteur"];
			$var->ts=$ts;
			$news=new news($var);
			$news->ajouter();
		}
	}
	
	if($_REQUEST["action"]=="editer_news"){
		if(($_REQUEST["titre"]!="")&&($_REQUEST["texte"]!="")&&($_REQUEST["auteur"]!="")&&($_REQUEST["date"]!="")){
			$tmp=preg_replace("/(\d{2})\/(\d{2})\/(\d{4})/","$3-$2-$1",$_REQUEST["date"]);
			//echo $tmp;
			$ts=strtotime($tmp);
			//echo $_REQUEST["date"]." ".$ts;
			$var=$sql->request_single("select * from ".CFG_MYSQL_PREFIX."news where id=".$_REQUEST["id"]);
			$news=new news($var);
			$news->titre=$_REQUEST["titre"];
			$news->texte=$_REQUEST["texte"];
			$news->auteur=$_REQUEST["auteur"];
			$news->ts=$ts;
			$news->maj();
		}
	}
	
	if($_REQUEST["action"]=="supprimer_news"){
		$sql->query("delete from ".CFG_MYSQL_PREFIX."news_commentaire where idNews=".$_REQUEST["id"]);
		$sql->query("delete from ".CFG_MYSQL_PREFIX."news where id=".$_REQUEST["id"]);
	}
}

$cfg_params=array();
$res=$sql->request("select * from ".CFG_MYSQL_PREFIX."module_config where module='news'");
foreach($res as $var){
	$cfg_params[$var->nom]=$var->valeur;
}

